//引入定义仓库
import { defineStore } from "pinia";

export const useUser = defineStore('user', {
    state: () => ({
        userInfo: JSON.parse(sessionStorage.getItem("userInfo")) || {
            id: '',
            username: '',
            realName: '',
            role: '',
            token: '',
            createTime: '',
            schoolNumber: '',
            email: '',
            classId: null,
            status: ''
        }
    }),
    actions: {
        setUserInfo(userInfo) {
            this.userInfo = { ...this.userInfo, ...userInfo };
            sessionStorage.setItem('userInfo', JSON.stringify(this.userInfo));
        },
        clearUserInfo() {
            this.userInfo = {
                id: '',
                username: '',
                realName: '',
                role: '',
                token: '',
                createTime: '',
                schoolNumber: '',
                email: '',
                classId: null,
                status: ''
            };
            sessionStorage.removeItem('userInfo');
            sessionStorage.removeItem('token');
        }
    },
});


